<!DOCTYPE HTML>
<html lang="en-US">
<head>
	<meta charset="UTF-8">
	<title>提取URL的搜索字符串中的参数</title>
</head>
<body>
	<h1>提取URL的搜索字符串中的参数</h1>
</body>
</html>
<script type="text/javascript">
function urlArgs(){
	var args = {};
	var query = location.search.substring(1);
	if(query){
		if(query.indexOf('=') == -1){
			alert('参数形式错误');
			return false;
		}else{
			var pairs = query.split('&');
			for(var i = 0; i < pairs.length; i++){
				var pos = pairs[i].indexOf('=');
				if(pos == -1) continue;
				var name = pairs[i].substring(0, pos);
				if(!name){
					alert('参数名不能为空');
					return false;
				}
				var value = pairs[i].substring(pos + 1);
				value = decodeURIComponent(value);
				args[name] = value;
			}
		}
	}else{
		alert('没有参数');
		return false;
	}
	return args;
}
</script>